//
//
//  Generated by StarUML(tm) C++ Add-In
//
//  @ Project : OOAD5T
//  @ File Name : CleanerController.cpp
//  @ Date : 2026-05-03
//  @ Author : 
//
//


#include "CleanerController.h"
#include "Timer.h"

const int PowerUpDuration = 5; // 파워업 지속 시간 (초)

CleanerController::CleanerController(EventBus* bus, HwCleaner* cleaner, Timer* timer)
    : isTurnOn(false),
      powerUp(false),
      cleaner(cleaner),
      timer(timer != nullptr ? timer : &defaultTimer) {
    bus->subScribeStartCleaning([this]() {
            this->turnOn();
        });
    bus->subScribeDetectedDust([this]() {
        this->CCpowerUp();
        });
    bus->subScribeAvoidObstacle([this](SensorProvider *sensor) {
        this->turnOff();
        });
    bus->subScribeTurnOff([this]() {
        this->turnOff();
        });
}   

void CleanerController::turnOn() {
    isTurnOn = true;
    cleaner->turnOn();
}

void CleanerController::turnOff() {
    isTurnOn = false;
    cleaner->turnOff();
}

void CleanerController::CCpowerUp() {
    cleaner->powerUp();
    timer->setTimer(PowerUpDuration, [this]() {
            this->CCpowerRestore();
        });
}

void CleanerController::CCpowerRestore() {
    cleaner->powerRestore();
}

